<?php /* PROJECTS $Id: vw_idx_proposed.php,v 1.22.6.3 2006/11/19 16:01:34 gregorerhardt Exp $ */
GLOBAL $AppUI, $projects, $pstatus, $psfilter;

$show_all_projects = $psfilter == P_ALL;

$perms =& $AppUI->acl();
$df = $AppUI->getPref('SHDATEFORMAT');
	// Let's check if the user submited the change status form

$canChangeStatus = $AppUI->user_type <= 5 && $psfilter != P_TEMPLATE;
?>

<form action='index.php' method='get'>
<table id="<?=$psfilter?>" width="100%" border="0" cellpadding="3" cellspacing="0" class="list">
<tr class="clickable">
	<th width="50px" nowrap="nowrap" id="project_color_identifier" onclick="setMode(this)">
		<?=$AppUI->_('Color')?>
	</th>
	<th nowrap="nowrap" id="project_name" onclick="setMode(this)">
		<?=$AppUI->_('Reference Name')?>
	</th>
	<th nowrap="nowrap" id="company_name" onclick="setMode(this)">
		<?=$AppUI->_('Company')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_start_date" onclick="setMode(this)">
		<?=$AppUI->_('Start')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_end_date" onclick="setMode(this)">
		<?=$AppUI->_('End')?>
	</th>
	<th width="70px" nowrap="nowrap" id="project_actual_end_date" onclick="setMode(this)">
		<?=$AppUI->_('Actual')?>
	</th>
	<th nowrap="nowrap" id="task_log_problem" onclick="setMode(this)">
		<?=$AppUI->_('P')?>
	</th>
	<th width="32px" nowrap="nowrap" id="user_username" onclick="setMode(this)">
		<?=$AppUI->_('Owner')?>
	</th>
	<th width="70px" nowrap="nowrap" id="total_tasks" onclick="setMode(this)">
		<?=$AppUI->_('Tasks')?>
		<a id="my_tasks" href="javascript:setMode(this)">(<?=$AppUI->_('My')?>)</a>
	</th>
	<? if($show_all_projects) { ?>
	<th width="60px" nowrap="nowrap"><?=$AppUI->_('Status')?></th>
	<? } ?>
<? if ($canChangeStatus) { ?>
	<th width="20px" nowrap="nowrap" class="last">
		<?=$AppUI->_('Set')?>
	</th>
<? } ?>
</tr>

<?php
$none = true;

$np = 1;
foreach ($projects as $row) {
	if (! $perms->checkModuleItem('projects', 'view', $row['project_id'])) {
		continue;
	}
	if ($show_all_projects || $row["project_status"] == $psfilter) {
		$none = false;
		$start_date = intval( @$row["project_start_date"] ) ? new CDate( $row["project_start_date"] ) : null;
		$end_date = intval( @$row["project_end_date"] ) ? new CDate( $row["project_end_date"] ) : null;
		$actual_end_date = intval( @$row["project_actual_end_date"] ) ? new CDate( $row["project_actual_end_date"] ) : null;
		$style = (( $actual_end_date > $end_date) && !empty($end_date)) ? 'style="color:red; font-weight:bold"' : '';

		$s = '<tr class="'.($np % 2 == 1 ? 'first' : 'second').'">'; $np++;
		$s .= '<td>'.
				'<div align="center" style="width: 100%; border: outset #eeeeee 1px;background-color:#' . $row["project_color_identifier"] . '">';
		$s .= '<font color="' . bestColor( $row["project_color_identifier"] ) . '">'
			. sprintf( "%.1f%%", $row["project_percent_complete"] )
			. '</font>';
		$s .= '</div></td>';

		$s .= '<td class="clickable" onclick="viewProject('.$row["project_id"].')">'.htmlspecialchars($row["project_name"], ENT_QUOTES ).'</td>';

		if ($perms->checkModuleItem('companies', 'access', $row['project_company'])) {
			$s .= '<td class="clickable" onclick="Company('.$row["project_company"].').show()" title="' . htmlspecialchars( $row["company_description"], ENT_QUOTES ) . '">' . htmlspecialchars( $row["company_name"], ENT_QUOTES ) . '</td>';
		} else {
			$s .= '<td>'.htmlspecialchars( $row['company_name'], ENT_QUOTES ).'</td>';
		}

		$s .= '<td align="center">'. ($start_date ? $start_date->format( $df ) : '-') .'</td>';
		$s .= '<td align="center">'. ($end_date ? $end_date->format( $df ) : '-') .'</td>';
		$s .= '<td align="center">';
		$s .= $actual_end_date ? '<a href="?m=tasks&a=view&task_id='.$row["critical_task"].'">' : '';
		$s .= $actual_end_date ? '<span '. $style.'>'.$actual_end_date->format( $df ).'</span>' : '-';
		$s .= $actual_end_date ? '</a>' : '';
		$s .= '</td>';
		$s .= '<td align="center">';
		$s .= $row['task_log_problem'] ? '<a href="?m=tasks&a=index&f=all&project_id='.$row["project_id"].'">' : '';
		$s .= $row['task_log_problem'] ? dPshowImage( './images/problem.gif', 12, 12, 'Problem', 'Problem' ): '-';
		$s .= $row['task_log_problem'] ? '</a>' : '';
		$s .= '</td>';
		$s .= '<td nowrap="nowrap">' . htmlspecialchars( $row["user_username"], ENT_QUOTES ) . '</td>';
		$s .= '<td align="center" nowrap="nowrap">';
		$s .= $row["total_tasks"] . ($row["my_tasks"] ? ' ('.$row["my_tasks"].')' : '');
		$s .= '</td>';
		if ($show_all_projects) {
			$s .= '<td align="center" nowrap="nowrap">';
			$s .= $pstatus[$row["project_status"]];
			$s .= '</td>';
		}

		if ($canChangeStatus) {
			$allow = !$show_all_projects || $row["project_status"] != P_TEMPLATE ? '' : 'disabled = "true"';
			$s .= '<td align="center">';
			if ($perms->checkModuleItem('projects', 'edit', $row['project_id']))
				$s .= '<input type="checkbox" name="project_id[]" value="'.$row["project_id"].'" '.$allow.'/>';
			else
				$s .= '&nbsp;';
		}

		$s .= '</tr>';
		echo $s;
	}
}
if ($none) {
	echo '<tr><td colspan="10">' . $AppUI->_( 'No projects available' ) . '</td></tr>';
} else {
	if ($canChangeStatus) {
?>
<tr>
	<td colspan="100%" align="right">
		<?php
			echo "<input type='submit' class='button' value='".$AppUI->_('Update status')."' />";
			echo "<input type='hidden' name='update_project_status' value='1' />";
			echo "<input type='hidden' name='m' value='projects' />";
			echo arraySelect( $pstatus, 'project_status', 'size="1" class="text"', P_ACTIVE, true );
		?>
	</td>
</tr>
<?
	}
}
?>
</table>
</form>
